2 $.widget("ncbi.preloaderWidget", {
5 url: '/static/header_footer_ajax/',
6 //url: '/sites/NCBI_SSI_Components@2.29/header_footer_ajax/',
7 footerSelector: '.subfooter',
10 '#resource-menu': 'resources-menu',
11 '#all-howtos-menu': 'howto-menu'
26 // Only one instance of this plugin is allowed
32 this.updateUrlFromMeta();
34 /*$.each(self.options.menuSelectors, function(selector, url) {
35 self.initMenu(selector, url);
42 * Check for instance of the plugin
46 var instance = this.element.data('headerFooterAjaxInstance');
47 if (typeof instance != "undefined")
52 this.element.data('headerFooterAjaxInstance', this);
56 updateUrlFromMeta: function()
58 var newUrl = $('meta[name="headerFooterUrl"]').attr('content');
59 if (typeof newUrl == "undefined")
64 this.options.url = newUrl;
68 initMenu: function(element, url)
70 var menuitem = $(element).find('a');
72 // Do not redirect if top level menu item clicked
73 menuitem.on('click', function(e) {
79 menuitem.on('mouseenter.preload focus.preload', { element: menuitem, url: this.options.url + url }, this.preloadMenu);
83 preloadMenu: function(event)
85 var element = event.data.element;
88 Load menu items and add them after main link
90 $.get(event.data.url + '?p$debugoutput=none', function(data) {
95 Once submenu is loaded - we are done, disconnect events
97 element.off('mouseenter.preload focus.preload');
100 Menu is supposed to appear when keyboard focus is received.
101 But it has just been loaded, so trigger "focus" again
103 if (event.type == 'focus')
105 element.trigger('focus');
109 initFooter: function()
111 var footer = $(this.options.footerSelector);
112 var scrollTop = $(document).scrollTop();
115 if (footer.length < 1)
120 this._browserHeight = $(window).height();
121 this._footerOffset = footer.offset().top;
124 Load footer if it is visible
125 (page height is less than browser height or page is scrolled to the footer)
127 if(this._footerOffset < scrollTop + this._browserHeight + 500)
129 this.loadFooter(footer);
131 /* Otherwise wait for user to scroll to the bottom */
134 $(window).on('scroll', { self: this, container: footer }, this.lazyLoadFooter);
138 loadFooter: function(container)
140 container.load(this.options.url + "footer-menu" + '?p$debugoutput=none', function() {
141 /* Add popup for external links (facebook, twitter, youtube) */
142 container.find('a').ncbiexternallink();
143 /* jQuery.ui.jig.scan('body', {
144 widgets: ['ncbiexternallink']
150 lazyLoadFooter: function(event)
152 var self = event.data.self;
153 var scrollTop = $(document).scrollTop();
154 if(scrollTop + self._browserHeight > self._footerOffset - self.options.footerPreloadPos)
156 self.loadFooter(event.data.container);
157 $(window).unbind("scroll", self.lazyLoadFooter);
166 $(document).preloaderWidget();